//引入 'myModele' 模块
var app = angular.module('app', ['myModule']);

app.controller('myCtrl', function($scope, $http){

    //设置分页的参数
    $scope.option = {
        curr: 1,  //当前页数
        all: 8,  //总页数
        count: 10,  //最多显示的页数，默认为10

        //点击页数的回调函数，参数page为点击的页数
        click: function (page) {
            console.log(page);
            //这里可以写跳转到某个页面等...
        }
    }
    
    
    $http.post("/ssm/getTotalPages").then(function (response) {
    	 console.log(response.data.total);
    	 $scope.option.all=response.data.total;	
    	 $scope.page = getRange($scope.option.curr, $scope.option.all, $scope.option.count);
    	
	});
    
    
    
    //返回页数范围（用来遍历）
    function getRange(curr, all, count) {
        //计算显示的页数
        curr = parseInt(curr);
        all = parseInt(all);
        count = parseInt(count);
        var from = curr - parseInt(count / 2);
        var to = curr + parseInt(count / 2) + (count % 2) - 1;
        //显示的页数容处理
        if (from <= 0) {
            from = 1;
            to = from + count - 1;
            if (to > all) {
                to = all;
            }
        }
        if (to > all) {
            to = all;
            from = to - count + 1;
            if (from <= 0) {
                from = 1;
            }
        }
        var range = [];
        for (var i = from; i <= to; i++) {
            range.push(i);
        }
        range.push('»');
        range.unshift('«');
        return range;
    }
    
    
});